const javascriptObfuscator = require("gulp-javascript-obfuscator");
const uglify = require("gulp-uglify");
const path = require("path");
const gulp = require("gulp");

const workSpaceDir = path.resolve(__dirname, "../");


function publish_old(targetPath) {
    return gulp.src(path.join(workSpaceDir, "bin/js/bundle.js"))
        // .pipe(javascriptObfuscator({
        //     compact: true,//输出单行
        //     controlFlowFlattening: false,
        //     deadCodeInjection: false,
        //     debugProtection: false,
        //     debugProtectionInterval: false,
        //     disableConsoleOutput: false, //屏蔽日志
        //     identifierNamesGenerator: 'hexadecimal',
        //     log: true,
        //     renameGlobals: false,
        //     rotateStringArray: true,
        //     selfDefending: true,
        //     shuffleStringArray: true,
        //     splitStrings: false,
        //     stringArray: true,
        //     stringArrayEncoding: false,
        //     stringArrayThreshold: 0.75,
        //     unicodeEscapeSequence: false
        // }))
        .pipe(javascriptObfuscator({
            log: false
        }))
        .pipe(gulp.dest(path.join(workSpaceDir, "release", targetPath, "js")))
}

function publish(targetPath) {
    return gulp.src(path.join(workSpaceDir, "bin/js/bundle.js"))
        .pipe(uglify({
            mangle: {
                eval: true
            },
            output: {
                ascii_only: true,
                /**美化js */
                beautify: false,
            },
            compress: {

            }

        }))
        .pipe(gulp.dest(path.join(workSpaceDir, "release", targetPath, "js")))
}


module.exports = publish;


